<!DOCTYPE html>












  


<html class="theme-next pisces use-motion" lang="zh-CN">
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">






















<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css?v=4.7.0">

<link rel="stylesheet" href="/css/main.css?v=7.1.2">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=7.1.2">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=7.1.2">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=7.1.2">


  <link rel="mask-icon" href="/images/logo.svg?v=7.1.2" color="#222">







<script id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    version: '7.1.2',
    sidebar: {"position":"left","display":"post","offset":12,"onmobile":false,"dimmer":false},
    back2top: true,
    back2top_sidebar: false,
    fancybox: false,
    fastclick: false,
    lazyload: false,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>


  




  <meta name="description" content="动态主机地址管理协议 动态主机配置协议（DHCP）是一种基于UDP协议且仅限于在局域网内部使用的网络协议  主要用于大型的局域网环境或者存在较多移动办公设备的局域网环境中  主要用途是为局域网内部的设备或网络供应商自动分配IP地址等参数  简单来说，DHCP协议就是让局域网中的主机自动获得网络参数的服务">
<meta name="keywords" content="DHCP">
<meta property="og:type" content="article">
<meta property="og:title" content="DHCP动态管理主机地址">
<meta property="og:url" content="https://lzz001.gitee.io/2019/09/11/DHCP动态管理主机地址/index.html">
<meta property="og:site_name" content="小智的博客">
<meta property="og:description" content="动态主机地址管理协议 动态主机配置协议（DHCP）是一种基于UDP协议且仅限于在局域网内部使用的网络协议  主要用于大型的局域网环境或者存在较多移动办公设备的局域网环境中  主要用途是为局域网内部的设备或网络供应商自动分配IP地址等参数  简单来说，DHCP协议就是让局域网中的主机自动获得网络参数的服务">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="https://gitee.com/lzz001/img/raw/master/DHCP/01%20%E7%A6%81%E6%AD%A2%E6%9C%AC%E5%9C%B0DHCP%E5%88%86%E9%85%8DIP%E5%9C%B0%E5%9D%80%E7%BB%99%E8%99%9A%E6%8B%9F%E6%9C%BA.png">
<meta property="og:image" content="https://gitee.com/lzz001/img/raw/master/DHCP/02%20%E7%A6%81%E7%94%A8WLAN%E5%92%8C%E4%BB%A5%E5%A4%AA%E7%BD%91.png">
<meta property="og:image" content="https://gitee.com/lzz001/img/raw/master/DHCP/03%20%E5%AE%A2%E6%88%B7%E7%AB%AF%E7%BD%91%E7%BB%9C%E4%BF%A1%E6%81%AF.png">
<meta property="og:image" content="https://gitee.com/lzz001/img/raw/master/DHCP/04%20DHCP%E9%85%8D%E7%BD%AE%E9%94%99%E8%AF%AF.png">
<meta property="og:updated_time" content="2019-09-11T07:12:27.227Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="DHCP动态管理主机地址">
<meta name="twitter:description" content="动态主机地址管理协议 动态主机配置协议（DHCP）是一种基于UDP协议且仅限于在局域网内部使用的网络协议  主要用于大型的局域网环境或者存在较多移动办公设备的局域网环境中  主要用途是为局域网内部的设备或网络供应商自动分配IP地址等参数  简单来说，DHCP协议就是让局域网中的主机自动获得网络参数的服务">
<meta name="twitter:image" content="https://gitee.com/lzz001/img/raw/master/DHCP/01%20%E7%A6%81%E6%AD%A2%E6%9C%AC%E5%9C%B0DHCP%E5%88%86%E9%85%8DIP%E5%9C%B0%E5%9D%80%E7%BB%99%E8%99%9A%E6%8B%9F%E6%9C%BA.png">





  
  
  <link rel="canonical" href="https://lzz001.gitee.io/2019/09/11/DHCP动态管理主机地址/">



<script id="page.configurations">
  CONFIG.page = {
    sidebar: "",
  };
</script>

  <title>DHCP动态管理主机地址 | 小智的博客</title>
  






  <script>
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?297412c3c8589eb0dc190e2d81f12097";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>







  <noscript>
  <style>
  .use-motion .motion-element,
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-title { opacity: initial; }

  .use-motion .logo,
  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-CN">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>
	<a href="https://github.com/zengzhiLai" target="_blank" class="github-corner" aria-label="View source on GitHub">
		<svg width="100" height="100" viewbox="0 0 250 250" style="fill:#151513; color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true">
			<path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"/>
			<path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"/><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"/>
		</svg>
	</a>
	<style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>
	
    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">小智的博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
    
      
        <p class="site-subtitle">慢即是快</p>
      
    
    
  </div>

  <div class="site-nav-toggle">
    <button aria-label="切换导航栏">
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>



<nav class="site-nav">
  
    <ul id="menu" class="menu">
      
        
        
        
          
          <li class="menu-item menu-item-home">

    
    
      
    

    

    <a href="/" rel="section"><i class="menu-item-icon fa fa-fw fa-home"></i> <br>首页</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-about">

    
    
      
    

    

    <a href="/about/" rel="section"><i class="menu-item-icon fa fa-fw fa-user"></i> <br>关于</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-tags">

    
    
      
    

    

    <a href="/tags/" rel="section"><i class="menu-item-icon fa fa-fw fa-tags"></i> <br>标签</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-categories">

    
    
      
    

    

    <a href="/categories/" rel="section"><i class="menu-item-icon fa fa-fw fa-th"></i> <br>分类</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-archives">

    
    
      
    

    

    <a href="/archives/" rel="section"><i class="menu-item-icon fa fa-fw fa-archive"></i> <br>归档</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-commonweal">

    
    
      
    

    

    <a href="/404/" rel="section"><i class="menu-item-icon fa fa-fw fa-heartbeat"></i> <br>公益 404</a>

  </li>

      
      
    </ul>
  

  

  
</nav>



  



</div>
    </header>

    


    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          
            

          
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://lzz001.gitee.io/2019/09/11/DHCP动态管理主机地址/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="小智">
      <meta itemprop="description" content="Java,Linux,Mysql">
      <meta itemprop="image" content="/images/zhi.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="小智的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">DHCP动态管理主机地址

              
            
          </h1>
        

        <div class="post-meta">

          
          
          

          
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              

              
                
              

              <time title="创建时间：2019-09-11 15:01:03 / 修改时间：15:12:27" itemprop="dateCreated datePublished" datetime="2019-09-11T15:01:03+08:00">2019-09-11</time>
            </span>
          

          
            

            
          

          
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/Linux/" itemprop="url" rel="index"><span itemprop="name">Linux</span></a></span>

                
                
              
            </span>
          

          
            
            
          

          
          

          
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
                 阅读次数： 
                <span class="busuanzi-value" id="busuanzi_value_page_pv"></span>
              </span>
            </span>
          

          <br>
          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="动态主机地址管理协议"><a href="#动态主机地址管理协议" class="headerlink" title="动态主机地址管理协议"></a>动态主机地址管理协议</h2><ul>
<li><p>动态主机配置协议（DHCP）是一种基于<strong>UDP协议</strong>且仅限于在<strong>局域网内部</strong>使用的网络协议</p>
</li>
<li><p>主要用于大型的局域网环境或者存在较多移动办公设备的局域网环境中</p>
</li>
<li><p>主要用途是为局域网内部的设备或网络供应商自动分配IP地址等参数</p>
</li>
<li><p>简单来说，DHCP协议就是让局域网中的主机自动获得网络参数的服务</p>
</li>
</ul>
<a id="more"></a>

<ul>
<li><p>DHCP涉及的常见术语：</p>
<blockquote>
<p><strong>作用域</strong>：一个完整的IP地址段，DHCP协议根据作用域来管理网络的分布、分配IP地址及其他配置参数</p>
<p><strong>超级作用域</strong>：用于管理处于同一个物理网络中的多个逻辑子网段。超级作用域中包含了可以统一管理的作用域列表</p>
<p><strong>排除范围</strong>：把作用域中的某些IP地址排除，确保这些IP地址不会分配给DHCP客户端</p>
<p><strong>地址池</strong>：在定义了DHCP的作用域并应用了排除范围后，剩余的用来动态分配给DHCP客户端的IP地址范围</p>
<p><strong>租约</strong>：DHCP客户端能够使用动态分配的IP地址的时间</p>
<p><strong>预约</strong>：保证网络中的特定设备总是获取到相同的IP地址</p>
</blockquote>
</li>
</ul>
<h2 id="部署dhcpd服务程序"><a href="#部署dhcpd服务程序" class="headerlink" title="部署dhcpd服务程序"></a><strong>部署dhcpd服务程序</strong></h2><ol>
<li><p><strong>安装dhcpd服务程序</strong></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span> yum install dhcp</span><br></pre></td></tr></table></figure>
</li>
<li><p><strong>查看dhcpd服务程序的配置文件内容</strong></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span> vim /etc/dhcp/dhcpd.conf</span><br><span class="line"><span class="meta">#</span></span><br><span class="line"><span class="meta">#</span> DHCP Server Configuration file.</span><br><span class="line"><span class="meta">#</span>   see /usr/share/doc/dhcp*/dhcpd.conf.example</span><br><span class="line"><span class="meta">#</span>   see dhcpd.conf(5) man page</span><br><span class="line"><span class="meta">#</span></span><br></pre></td></tr></table></figure>

</li>
</ol>
<h2 id="dhcpd服务常见参数以及作用"><a href="#dhcpd服务常见参数以及作用" class="headerlink" title="dhcpd服务常见参数以及作用"></a>dhcpd服务常见参数以及作用</h2><table>
<thead>
<tr>
<th>参数</th>
<th>作用</th>
</tr>
</thead>
<tbody><tr>
<td>ddns-update-style 类型</td>
<td>定义DNS服务动态更新的类型，<br>类型包括： none（不支持动态更新）、<br>interim（互动更新模式）与ad-hoc（特殊更新模式）</td>
</tr>
<tr>
<td>allow/ignore client-updates</td>
<td>允许/忽略客户端更新DNS记录</td>
</tr>
<tr>
<td>default-lease-time 21600</td>
<td>默认超时时间</td>
</tr>
<tr>
<td>max-lease-time 43200</td>
<td>最大超时时间</td>
</tr>
<tr>
<td>option domain-name-servers 8.8.8.8</td>
<td>定义DNS服务器地址</td>
</tr>
<tr>
<td>option domain-name “domain.org”</td>
<td>定义DNS域名</td>
</tr>
<tr>
<td>range</td>
<td>定义用于分配的IP地址池</td>
</tr>
<tr>
<td>option subnet-mask</td>
<td>定义客户端的子网掩码</td>
</tr>
<tr>
<td>option routers</td>
<td>定义客户端的网关地址</td>
</tr>
<tr>
<td>broadcast-address 广播地址</td>
<td>定义客户端的广播地址</td>
</tr>
<tr>
<td>ntp-server IP地址</td>
<td>定义客户端的网络时间服务器（NTP）</td>
</tr>
<tr>
<td>nis-servers IP地址</td>
<td>定义客户端的NIS域服务器的地址</td>
</tr>
<tr>
<td>hardware 硬件类型 MAC地址</td>
<td>指定网卡接口的类型与MAC地址</td>
</tr>
<tr>
<td>server-name 主机名</td>
<td>向DHCP客户端通知DHCP服务器的主机名</td>
</tr>
<tr>
<td>fixed-address IP地址</td>
<td>将某个固定的IP地址分配给指定主机</td>
</tr>
<tr>
<td>time-offset 偏移差</td>
<td>指定客户端与格林尼治时间的偏移差</td>
</tr>
</tbody></table>
<h2 id="自动管理IP地址"><a href="#自动管理IP地址" class="headerlink" title="自动管理IP地址"></a>自动管理IP地址</h2><ol>
<li><p><strong>配置dhcpd服务程序</strong></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span> vim /etc/dhcp/dhcpd.conf</span><br><span class="line">ddns-update-style none; #设置DNS服务不自动进行动态更新</span><br><span class="line">ignore client-updates; #忽略客户端更新DNS记录</span><br><span class="line">subnet 192.168.40.0 netmask 255.255.255.0 &#123; #作用域为192.168.40.0/24网段</span><br><span class="line">        range 192.168.40.50 192.168.40.100; #IP地址池为192.168.40.50-100</span><br><span class="line">        option subnet-mask 255.255.255.0; #客户端默认子网掩码</span><br><span class="line">        option routers 192.168.40.1; #客户端的网关地址</span><br><span class="line">        option domain-name "zengzhilai.com"; #默认搜索域</span><br><span class="line">        option domain-name-servers 192.168.40.1; #客户端的DNS地址</span><br><span class="line">        default-lease-time 21600; #默认租约时间(单位:s)</span><br><span class="line">        max-lease-time 43200; #最大预约时间</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p><strong>启动dhcpd服务，并加入开机启动项</strong></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span> systemctl start dhcpd</span><br><span class="line"><span class="meta">#</span> systemctl enable dhcpd</span><br><span class="line">ln -s '/usr/lib/systemd/system/dhcpd.service' '/etc/systemd/system/multi-user.target.wants/dhcpd.service'</span><br></pre></td></tr></table></figure>
</li>
<li><p><strong>Linux客户机测试</strong></p>
<p>Linux客户机先虚拟网络编辑设置，去掉下图的功能，避免与自己配置的dhcpd服务程序产生冲突</p>
<p><img src="https://gitee.com/lzz001/img/raw/master/DHCP/01%20%E7%A6%81%E6%AD%A2%E6%9C%AC%E5%9C%B0DHCP%E5%88%86%E9%85%8DIP%E5%9C%B0%E5%9D%80%E7%BB%99%E8%99%9A%E6%8B%9F%E6%9C%BA.png" alt="禁止本地DHCP分配IP地址给虚拟机"></p>
<p>客户机 <code>Linux6.8</code> 重启网络服务，查看此时的IP地址</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span> service network restart</span><br><span class="line">正在关闭接口 eth0：                                        [确定]</span><br><span class="line">关闭环回接口：                                             [确定]</span><br><span class="line">弹出环回接口：                                             [确定]</span><br><span class="line">弹出界面 eth0： </span><br><span class="line">正在决定 eth0 的 IP 信息...完成。</span><br><span class="line">                                                           [确定]</span><br><span class="line"><span class="meta">#</span> ifconfig</span><br><span class="line">eth0      Link encap:Ethernet  HWaddr 00:50:56:3E:86:08  </span><br><span class="line">          inet addr:192.168.40.50  Bcast:192.168.40.255  Mask:255.255.255.0</span><br><span class="line">          inet6 addr: fe80::250:56ff:fe3e:8608/64 Scope:Link</span><br><span class="line">          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1</span><br><span class="line">          RX packets:828 errors:0 dropped:0 overruns:0 frame:0</span><br><span class="line">          TX packets:249 errors:0 dropped:0 overruns:0 carrier:0</span><br><span class="line">          collisions:0 txqueuelen:1000 </span><br><span class="line">          RX bytes:58920 (57.5 KiB)  TX bytes:23319 (22.7 KiB)</span><br><span class="line"></span><br><span class="line">lo        Link encap:Local Loopback  </span><br><span class="line">          inet addr:127.0.0.1  Mask:255.0.0.0</span><br><span class="line">          inet6 addr: ::1/128 Scope:Host</span><br><span class="line">          UP LOOPBACK RUNNING  MTU:16436  Metric:1</span><br><span class="line">          RX packets:256 errors:0 dropped:0 overruns:0 frame:0</span><br><span class="line">          TX packets:256 errors:0 dropped:0 overruns:0 carrier:0</span><br><span class="line">          collisions:0 txqueuelen:0 </span><br><span class="line">          RX bytes:28791 (28.1 KiB)  TX bytes:28791 (28.1 KiB)</span><br></pre></td></tr></table></figure>
</li>
<li><p><strong>Window10客户端测试</strong></p>
<p>禁用WLAN、以太网</p>
<p><img src="https://gitee.com/lzz001/img/raw/master/DHCP/02%20%E7%A6%81%E7%94%A8WLAN%E5%92%8C%E4%BB%A5%E5%A4%AA%E7%BD%91.png" alt="禁用WLAN和以太网"></p>
<p>重启（即禁用再启用）VMware Network Adapter VMnet8</p>
<p>在CMD中输入<code>ipconfig/all</code>查看网络信息</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">C:\Users\zengzhilai&gt;ipconfig/all</span><br><span class="line">......</span><br><span class="line">以太网适配器 VMware Network Adapter VMnet8:</span><br><span class="line"></span><br><span class="line">   连接特定的 DNS 后缀 . . . . . . . : zengzhilai.com</span><br><span class="line">   描述. . . . . . . . . . . . . . . : VMware Virtual Ethernet Adapter for VMnet8</span><br><span class="line">   物理地址. . . . . . . . . . . . . : 00-50-56-C0-00-08</span><br><span class="line">   DHCP 已启用 . . . . . . . . . . . : 是</span><br><span class="line">   自动配置已启用. . . . . . . . . . : 是</span><br><span class="line">   本地链接 IPv6 地址. . . . . . . . : fe80::f43d:45b2:8490:738e%14(首选)</span><br><span class="line">   IPv4 地址 . . . . . . . . . . . . : 192.168.40.51(首选)</span><br><span class="line">   子网掩码  . . . . . . . . . . . . : 255.255.255.0</span><br><span class="line">   获得租约的时间  . . . . . . . . . : 2019年9月10日 3:10:56</span><br><span class="line">   租约过期的时间  . . . . . . . . . : 2019年9月10日 9:10:56</span><br><span class="line">   默认网关. . . . . . . . . . . . . : 192.168.40.1</span><br><span class="line">   DHCP 服务器 . . . . . . . . . . . : 192.168.40.131</span><br><span class="line">   DHCPv6 IAID . . . . . . . . . . . : 251678806</span><br><span class="line">   DHCPv6 客户端 DUID  . . . . . . . : 00-01-00-01-24-DB-67-0F-74-C6-3B-9A-E7-E9</span><br><span class="line">   DNS 服务器  . . . . . . . . . . . : 192.168.40.1</span><br><span class="line">   TCPIP 上的 NetBIOS  . . . . . . . : 已启用</span><br></pre></td></tr></table></figure>
</li>
<li><p><strong>查看租约数据库<code>/var/lib/dhcpd/dhcpd.leases</code></strong></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span> cat /var/lib/dhcpd/dhcpd.leases</span><br><span class="line"><span class="meta">#</span> The format of this file is documented in the dhcpd.leases(5) manual page.</span><br><span class="line"><span class="meta">#</span> This lease file was written by isc-dhcp-4.2.5</span><br><span class="line"></span><br><span class="line">server-duid "\000\001\000\001%\011UV\000\014)J \342";</span><br><span class="line"></span><br><span class="line">lease 192.168.40.50 &#123;</span><br><span class="line">  starts 1 2019/09/09 19:00:58;</span><br><span class="line">  ends 2 2019/09/10 01:00:58;</span><br><span class="line">  cltt 1 2019/09/09 19:00:58;</span><br><span class="line">  binding state active;</span><br><span class="line">  next binding state free;</span><br><span class="line">  rewind binding state free;</span><br><span class="line">  hardware ethernet 00:50:56:3e:86:08;</span><br><span class="line">&#125;</span><br><span class="line">lease 192.168.40.51 &#123;</span><br><span class="line">  starts 1 2019/09/09 19:10:56;</span><br><span class="line">  ends 2 2019/09/10 01:10:56;</span><br><span class="line">  cltt 1 2019/09/09 19:10:56;</span><br><span class="line">  binding state active;</span><br><span class="line">  next binding state free;</span><br><span class="line">  rewind binding state free;</span><br><span class="line">  hardware ethernet 00:50:56:c0:00:08;</span><br><span class="line">  uid "\001\000PV\300\000\010";</span><br><span class="line">  client-hostname "LAPTOP-VFVIEPCS";</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

</li>
</ol>
<h2 id="分配固定IP地址"><a href="#分配固定IP地址" class="headerlink" title="分配固定IP地址"></a>分配固定IP地址</h2><ol>
<li><p><strong>获取boss主机的MAC地址</strong></p>
<p>先启动dhcpd服务程序，为boss的主机分配一个IP地址，然后查看DHCP服务器本地的日志文件（保存这次的IP地址分配记录），获取主机的MAC地址</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span> tail -f /var/log/messages</span><br><span class="line">Sep 10 21:47:36 localhost dhcpd: DHCPOFFER on 192.168.40.51 to 00:50:56:c0:00:08 (LAPTOP-VFVIEPCS) via eno16777728</span><br><span class="line">Sep 10 21:47:37 localhost dhcpd: DHCPREQUEST for 192.168.40.51 (192.168.40.131) from 00:50:56:c0:00:08 (LAPTOP-VFVIEPCS) via eno16777728</span><br><span class="line">Sep 10 21:47:37 localhost dhcpd: DHCPACK on 192.168.40.51 to 00:50:56:c0:00:08 (LAPTOP-VFVIEPCS) via eno16777728</span><br><span class="line">Sep 10 21:47:38 localhost kernel: e1000: eno16777728 NIC Link is Down</span><br><span class="line">Sep 10 21:47:38 localhost NetworkManager[1227]: &lt;info&gt; (eno16777728): link disconnected (deferring action for 4 seconds)</span><br><span class="line">Sep 10 21:47:42 localhost NetworkManager[1227]: &lt;info&gt; (eno16777728): link disconnected (calling deferred action)</span><br><span class="line">Sep 10 21:47:44 localhost kernel: e1000: eno16777728 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: None</span><br><span class="line">Sep 10 21:47:44 localhost NetworkManager[1227]: &lt;info&gt; (eno16777728): link connected</span><br><span class="line">Sep 10 21:50:01 localhost systemd: Starting Session 31 of user root.</span><br><span class="line">Sep 10 21:50:01 localhost systemd: Started Session 31 of user root.</span><br></pre></td></tr></table></figure>
</li>
<li><p><strong>配置dhcpd服务文件</strong></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span> vim /etc/dhcp/dhcpd.conf</span><br><span class="line">ddns-update-style none;</span><br><span class="line">ignore client-updates;</span><br><span class="line">subnet 192.168.40.0 netmask 255.255.255.0 &#123;</span><br><span class="line">        range 192.168.40.50 192.168.40.100;</span><br><span class="line">        option subnet-mask 255.255.255.0;</span><br><span class="line">        option routers 192.168.40.1;</span><br><span class="line">        option domain-name "zengzhilai.com";</span><br><span class="line">        option domain-name-servers 192.168.40.1;</span><br><span class="line">        default-lease-time 21600;</span><br><span class="line">        max-lease-time 43200;</span><br><span class="line">        #主机分配固定IP地址</span><br><span class="line">        host boss &#123; #boss是主机名(随意取)</span><br><span class="line">                hardware ethernet 00:50:56:c0:00:08; #主机的MAC地址</span><br><span class="line">                fixed-address 192.168.40.88; #欲指定的IP地址</span><br><span class="line">        &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p><strong>查看boss主机的IP地址</strong></p>
<p><img src="https://gitee.com/lzz001/img/raw/master/DHCP/03%20%E5%AE%A2%E6%88%B7%E7%AB%AF%E7%BD%91%E7%BB%9C%E4%BF%A1%E6%81%AF.png" alt="客户端网络信息"></p>
</li>
</ol>
<p><strong>注意：</strong>有时候<strong>dhcpd服务启动没报错不代表配置参数没错</strong>，下面的出错点在<code>hardware ehternet</code>这里，很明显拼错单词了，应该是<code>ethernet</code></p>
<p><img src="https://gitee.com/lzz001/img/raw/master/DHCP/04%20DHCP%E9%85%8D%E7%BD%AE%E9%94%99%E8%AF%AF.png" alt="DHCP配置错误"></p>

      
    </div>

    

    
    
    

    

    
      
    
    

    

    <footer class="post-footer">
      
        
          
        
        <div class="post-tags">
          
            <a href="/tags/DHCP/" rel="tag"># DHCP</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2019/09/03/使用MariaDB数据库管理系统/" rel="next" title="使用MariaDB数据库管理系统">
                <i class="fa fa-chevron-left"></i> 使用MariaDB数据库管理系统
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2019/09/18/org-h2-jdbc-JdbcSQLInvalidAuthorizationSpecException-Wrong-user-name-or-password-28000-199/" rel="prev" title="org.h2.jdbc.JdbcSQLInvalidAuthorizationSpecException: Wrong user name or password [28000-199]">
                org.h2.jdbc.JdbcSQLInvalidAuthorizationSpecException: Wrong user name or password [28000-199] <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>


  </div>


          </div>
          

  
    <div class="comments" id="gitalk-container">
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/images/zhi.jpg" alt="小智">
            
              <p class="site-author-name" itemprop="name">小智</p>
              <div class="site-description motion-element" itemprop="description">Java,Linux,Mysql</div>
          </div>

          
            <nav class="site-state motion-element">
              
                <div class="site-state-item site-state-posts">
                
                  <a href="/archives/">
                
                    <span class="site-state-item-count">22</span>
                    <span class="site-state-item-name">日志</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-categories">
                  
                    
                      <a href="/categories/">
                    
                  
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">5</span>
                    <span class="site-state-item-name">分类</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-tags">
                  
                    
                      <a href="/tags/">
                    
                  
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">37</span>
                    <span class="site-state-item-name">标签</span>
                  </a>
                </div>
              
            </nav>
          

          

          

          

          

          
          

          
            
          
          

        </div>
      </div>

      
      <!--noindex-->
        <div class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
            
            
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#动态主机地址管理协议"><span class="nav-number">1.</span> <span class="nav-text">动态主机地址管理协议</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#部署dhcpd服务程序"><span class="nav-number">2.</span> <span class="nav-text">部署dhcpd服务程序</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#dhcpd服务常见参数以及作用"><span class="nav-number">3.</span> <span class="nav-text">dhcpd服务常见参数以及作用</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#自动管理IP地址"><span class="nav-number">4.</span> <span class="nav-text">自动管理IP地址</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#分配固定IP地址"><span class="nav-number">5.</span> <span class="nav-text">分配固定IP地址</span></a></li></ol></div>
            

          </div>
        </div>
      <!--/noindex-->
      

      

    </div>
  </aside>
  


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love" id="animate">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">小智</span>

  

  
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
    
      <span class="post-meta-item-text">站点阅读时长 &asymp;</span>
    
    <span title="站点阅读时长">2:07</span>
  
</div>









        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="post-meta-item-icon">
      <i class="fa fa-user"></i>
    </span>
    <span class="site-uv" title="总访客量">
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
    </span>
  

  
    <span class="post-meta-divider">|</span>
  

  
    <span class="post-meta-item-icon">
      <i class="fa fa-eye"></i>
    </span>
    <span class="site-pv" title="总访问量">
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
    </span>
  
</div>









        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

    

    
  </div>

  

<script>
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>


























  
  <script src="/lib/jquery/index.js?v=3.4.1"></script>

  
  <script src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>


  


  <script src="/js/utils.js?v=7.1.2"></script>

  <script src="/js/motion.js?v=7.1.2"></script>



  
  


  <script src="/js/affix.js?v=7.1.2"></script>

  <script src="/js/schemes/pisces.js?v=7.1.2"></script>



  
  <script src="/js/scrollspy.js?v=7.1.2"></script>
<script src="/js/post-details.js?v=7.1.2"></script>



  


  <script src="/js/next-boot.js?v=7.1.2"></script>


  

  

  

  


  
    

<script src="//cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.js"></script>



<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.css">



<script src="//cdn.jsdelivr.net/npm/js-md5@0.7.3/src/md5.min.js"></script>

<script>
  var gitalk = new Gitalk({
    clientID: '4a3937b2ec1408fa593c',
    clientSecret: 'bb11519c1d0aafd8540c58fe182487d24b1a1a6f',
    repo: 'zengzhiLai.github.io',
    owner: 'zengzhiLai',
    admin: ['zengzhiLai'],
    id: md5(location.pathname),
    
      language: window.navigator.language || window.navigator.userLanguage,
    
    distractionFreeMode: 'true'
  });
  gitalk.render('gitalk-container');
</script>

  


  




  

  

  

  

  

  
  <script>
    (function(){
      var bp = document.createElement('script');
      var curProtocol = window.location.protocol.split(':')[0];
      bp.src = (curProtocol === 'https') ? 'https://zz.bdstatic.com/linksubmit/push.js' : 'http://push.zhanzhang.baidu.com/push.js';
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(bp, s);
    })();
  </script>


  

  

  

  

  

  

  

  

</body>
</html>
<!-- 页面点击小红心 -->
	<script type="text/javascript" src="js/schemes/clicklove.js"></script>